package com.cl.utility.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * 配置webConfig拦截器
 *
 * @author dell
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
    }

    /**
     * 添加拦截器配置
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加不需要拦截的路径 白名单
        String[] patterns = {"/", "/demo/*", "/token/*",};
        List<String> list = Arrays.asList(patterns);
        registry.addInterceptor(new TokenInterceptor())
                // 配置不拦截的
                .excludePathPatterns(list)
                // 拦截所有
                .addPathPatterns("/**");
    }
}
